<?php
	$id = $_GET["id"];
	$comment = $_GET["comment"];
	$username = $_SESSION['login_username'];
	$todaydate = date("Y-m-d");
	$todaytime  = date("G:i:s");

	$con = mysql_connect("localhost","progin","progin");
				
	if (!$con) {
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("progin_171_13509045", $con) or die("Cannot find database");
	
	$sql = "INSERT INTO komentar (id_komentar, komentar, username, id_konten, tanggal, waktu) VALUES ('', '$comment', '$username', '$id', '$todaydate', '$todaytime')";
	$result = mysql_query($sql);
	$sql = "INSERT INTO commentsorter SELECT * FROM komentar ORDER BY tanggal, waktu DESC";
	$result = mysql_query($sql);
	$sql= "SELECT * FROM commentsorter WHERE id_konten='$id'";
	$result = mysql_query($sql);
	
	while ($row = mysql_fetch_array($result)) {
		$commentID = $row['id_komentar'];
		print '<div class="commentlist">
				<div class="commentator">';
		echo $row['username'];
		print '</div>
				<div class="dateformat">';
		echo $row['tanggal'];
		echo " at ";
		echo $row['waktu'];
		print '</div>
				<div class="commenttext">';
		echo $row['komentar'];
		echo "</div>
				<input type='button' id='deletebutton' value='Delete Comment' onclick=\"deleteComment('$commentID', '$id');\"/></input>
				</div>";
	}
	
	$sql ="TRUNCATE TABLE commentsorter";
	$result = mysql_query($sql);
					
	mysql_close($con);
?>